//
//  STSloganController.swift
//  SlowTrajectory
//
//  Created by iOS-Czz on 2023/10/23.
//

import UIKit
import WMZDialog
class STSloganController: STProjectBaseController {
    lazy var viewModel: STSloganViewModel = {
        return STSloganViewModel()
    }()
    lazy var memorialModel: STMemorailViewModel = {
        return STMemorailViewModel()
    }()
    @IBOutlet var setButton: UIButton!
    @IBOutlet var headImageView: UIImageView!
    @IBOutlet var dayLabel: UILabel!
    
    @IBOutlet var contentTV: UITextView!
    @IBOutlet var bgImageView: UIImageView!
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        getData()
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        self.wx_navigationBar.isHidden = true
        checkMemorialRemind()
        // Do any additional setup after loading the view.
    }
    func getData(){
        self.viewModel.loadData { model in
            self.dayLabel.text = model.day
            self.headImageView.image = UIImage.loadImage((model.bg)!)
            self.bgImageView.image = UIImage.loadImage((model.bg)!)
            self.contentTV.text = model.slogan
        }
    }
    
    func checkMemorialRemind(){
        var needRemind = false
        self.memorialModel.getPageData(1) { models in
            for model in models {
                let (nextReminderDate, daysUntilReminder) = String.calculateNextReminderDate(from: model.date, withWay: model.way)
                if daysUntilReminder < 7 {
                    needRemind = true
                    return
                }
            }
        }
        
        if needRemind {
            let param = WMZDialogParam()
            param.wTitle = "温馨提示"
            param.wMessage = "您有纪念日快到了，去看看吧"
            param.wOKTitle = "去看看"
            param.wEventOKFinish = {(anyId:Any?,otherData:Any?)in
                self.navigationController?.tabBarController?.selectedIndex = 2
            }
            _ =  WMZDialog().wStartParam(param)
        }
    }
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        self.setButton.addDashedBorder(color: .black, lineWidth: 1, cornerRadius: 15)
    }
    @IBAction func setSloganAction(_ sender: Any) {
        self.navigationController?.pushViewController(STSetSloganController(), animated: true)
    }
    
    
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
